package com.relytosoft.mizar.media.analyze.services.service.behavior.impl;

import com.relytosoft.mizar.media.alarm.api.entity.Alarm;
import com.relytosoft.mizar.media.alarm.api.feign.AlarmFeignInService;
import com.relytosoft.mizar.media.analyze.services.service.behavior.AyBehaviorAlarmService;
import com.relytosoft.mizar.media.analyze.services.service.system.AyUploadImageService;
import com.relytosoft.mizar.media.common.entity.pojo.dto.AyDispositionPlanDto;
import com.relytosoft.mizar.media.common.entity.pojo.request.btdl.common.BtdlBehaviorDataReq;
import com.relytosoft.mizar.media.common.enums.UpLoadFileEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wss
 * @version 1.0
 * @date 2022/6/22 14:08
 */
@Service
public class AyBehaviorAlarmServiceImpl implements AyBehaviorAlarmService {

    @Autowired
    AlarmFeignInService alarmFeignInService;
    @Autowired
    AyUploadImageService ayUploadImageService;

    @Override
    public void behaviorAlarm(AyDispositionPlanDto dispositionPlanDto, BtdlBehaviorDataReq btdlBehaviorDataReq) {
        rawBehaviorUrlReplace(btdlBehaviorDataReq);
        Alarm alarm = Alarm.buildBehaviorAlarm(dispositionPlanDto, btdlBehaviorDataReq);
        alarmFeignInService.handTaskAlarm(alarm);
    }

    /**
     * 行为分析任务原始数据图片替换
     *
     * @param btdlBehaviorDataReq
     */
    public void rawBehaviorUrlReplace(BtdlBehaviorDataReq btdlBehaviorDataReq) {
        String base64FrameUpload = ayUploadImageService.base64FrameUpload(btdlBehaviorDataReq.getImageData(),
                btdlBehaviorDataReq.getLeftTopX(),
                btdlBehaviorDataReq.getLeftTopY(),
                btdlBehaviorDataReq.getRightBtmX(),
                btdlBehaviorDataReq.getRightBtmY(),
                UpLoadFileEnum.ALGO_BEHAVIOR.getCode());
        btdlBehaviorDataReq.setImageData(base64FrameUpload);
    }

}
